<?php

class TicketUtils {
	
	/**
	 * Metoda przypisuje super użytkownika dla zgłoszenia użytkownika
	 * @param $ticket zgłoszenie
	 * @param $suser super użytkownik 
	 */
	public static function assignSuperUser(Ticket $ticket, User $suser) {
		return TicketUtils::assignSuperUserById ( $ticket->getId (), $suser->getId () );
	}
	
	/**
	 * Metoda przypisuje super użytkownika dla zgłoszenia użytkownika
	 * @param $ticketId identyfikator zgłoszenia
	 * @param $suserId identyfikator super użytkownika 
	 */
	public static function assignSuperUserById($ticketId, $suserId) {
		return Manager::getInstance ()->execute ( new TicketAssignSuperUserCommand ( $ticketId, $suserId ) );
	}
	
	/**
	 * Metoda usuwa zgloszenie z bazy
	 * @param $ticket zgloszenie
	 * @return flaga czy udało się usunąć
	 */
	public static function remove(Ticket $ticket) {
		return TicketUtils::removeById ( $ticket->getId () );
	}
	
	/**
	 * Metoda usuwa zgłoszenie z bazy o podanym id
	 * @param $ticketId id zgłoszenia
	 * @return flaga czy udało się usunąć
	 */
	public static function removeById($ticketId) {
		return Manager::getInstance ()->execute ( new TicketDeleteCommand ( $ticketId ) );
	}
	
	/** 
	 * Metoda dodaje zgloszenie do repozytorium
	 * @param $ticket zgłoszenie
	 */
	public static function add(Ticket &$ticket) {
		$tid = Manager::getInstance ()->execute ( new TicketAddCommand ( $ticket ) );
		if(VariableUtils::isNumber($tid)){
			$ticket->setId($tid);
		}
	}
	
	/**
	 * 
	 * @param TicketSearchControls $controls
	 * @return unknown_type
	 */
	public static function find(TicketSearchControls $controls) {
		return Manager::getInstance ()->execute ( new TicketFindCommand ( $controls ) );
	}
	
	/**
	 * Metoda pobiera zgloszenie o danym identyfikatorze
	 * @param $id identyfikator zgloszenia
	 * @return Ticket 
	 */
	public static function get($id) {
		return Manager::getInstance ()->execute ( new TicketGetCommand ( $id ) );
	}
	
	/**
	 * 
	 * @param $desc
	 * @return unknown_type
	 */
	public static function modifyDescription(TicketDescription $desc) {
		return Manager::getInstance ()->execute ( new TicketDescriptionModifyCommand ( $desc ) );
	}
	
	/**
	 * 
	 * @param TicketDescription $desc
	 * @return unknown_type
	 */
	public static function addDescription(TicketDescription $desc) {
		return Manager::getInstance ()->execute ( new TicketDescriptionAddCommand ( $desc ) );
	}
	
	/**
	 * 
	 * @param $id
	 * @return unknown_type
	 */
	public static function removeDescription($id) {
		return Manager::getInstance ()->execute ( new TicketDescriptionDeleteCommand ( $id ) );
	}
	
	public static function unActive($ticketId){
		return Manager::getInstance ()->execute ( new TicketUnActiveCommand ( $ticketId ) );
	}
	
	public static function createTicket($usid, $uid, $desc){
		$result = new Ticket();
		$result->setUsid($usid);
		$ticketDesc = new TicketDescription();
		$ticketDesc->set($desc);
		$ticketDesc->setUserId($uid);
		$result->add($ticketDesc);
		return $result;		
	}
}

?>